package com.eshop.modules.customer.service.impl;

import java.io.IOException;
import java.util.Iterator;
import com.eshop.utils.FileUtil;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.ArrayList;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.eshop.common.utils.QueryHelpPlus;
import java.util.List;
import com.github.pagehelper.PageInfo;
import com.eshop.modules.customer.service.dto.StoreCustomerDto;
import com.eshop.domain.PageResult;
import org.springframework.data.domain.Pageable;
import com.eshop.modules.customer.service.dto.StoreCustomerQueryCriteria;
import com.eshop.dozer.service.IGenerator;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import com.eshop.modules.customer.service.StoreCustomerService;
import com.eshop.modules.customer.domain.StoreCustomer;
import com.eshop.modules.customer.service.mapper.StoreCustomerMapper;
import com.eshop.common.service.impl.BaseServiceImpl;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = { Exception.class })
public class StoreCustomerServiceImpl extends BaseServiceImpl<StoreCustomerMapper, StoreCustomer> implements StoreCustomerService
{
    private final IGenerator generator;
    
    public PageResult<StoreCustomerDto> queryAll(final StoreCustomerQueryCriteria criteria, final Pageable pageable) {
        this.getPage(pageable);
        final PageInfo<StoreCustomer> page = (PageInfo<StoreCustomer>)new PageInfo((List)this.queryAll(criteria));
        return (PageResult<StoreCustomerDto>)this.generator.convertPageInfo((PageInfo)page, (Class)StoreCustomerDto.class);
    }
    
    public List<StoreCustomer> queryAll(final StoreCustomerQueryCriteria criteria) {
        return (List<StoreCustomer>)(this.baseMapper).selectList(QueryHelpPlus.getPredicate((Object)StoreCustomer.class, (Object)criteria));
    }
    
    public void download(final List<StoreCustomerDto> all, final HttpServletResponse response) throws IOException {
        final List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        for (final StoreCustomerDto yxStoreCustomer : all) {
            final Map<String, Object> map = new LinkedHashMap<String, Object>();
            map.put("用户昵称", yxStoreCustomer.getNickName());
            map.put("openId", yxStoreCustomer.getOpenId());
            map.put("备注", yxStoreCustomer.getRemark());
            map.put("添加时间", yxStoreCustomer.getCreateTime());
            map.put("修改时间", yxStoreCustomer.getUpdateTime());
            map.put(" isDel", yxStoreCustomer.getIsDel());
            map.put("是否启用", yxStoreCustomer.getIsEnable());
            list.add(map);
        }
        FileUtil.downloadExcel((List)list, response);
    }
    
    public StoreCustomerServiceImpl(final IGenerator generator) {
        this.generator = generator;
    }
}
